using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using DL;
/// <summary>
/// Summary description for StatusDAL
/// </summary>
namespace DAL 
{
    
    public class StatusDAL  : BaseDAL
    {
    	#region Private Variables

		#endregion
		
 #region Public Constructors
        public StatusDAL()
        {
            //
            // TODO: Add constructor logic here
            //
            
        }
 #endregion       

	
		
#region Public Methods
        public int Insert(StatusDL objStatusDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
Sqlparam.Value = objStatusDL.Name;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsPublic", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsPublic;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsNews", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsNews;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsProduct", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsProduct;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsMenu", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsMenu;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
Sqlparam.Direction = ParameterDirection.ReturnValue;
Sqlcomm.Parameters.Add(Sqlparam);

           
            int result =base.ExecuteNoneQuery(Sqlcomm);
            
            if(!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
				result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(StatusDL objStatusDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objStatusDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@Name", SqlDbType.NVarChar);
Sqlparam.Value = objStatusDL.Name;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsPublic", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsPublic;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsNews", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsNews;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsProduct", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsProduct;
Sqlcomm.Parameters.Add(Sqlparam);

Sqlparam = new SqlParameter("@IsMenu", SqlDbType.Bit);
Sqlparam.Value = objStatusDL.IsMenu;
Sqlcomm.Parameters.Add(Sqlparam);


            
            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            
             if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);
                
            return result;

           
        }

        public int Delete(StatusDL objStatusDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objStatusDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);


            
            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

         public int DeleteAll()
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_DeleteAll";

            int result=base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public StatusDL Select(StatusDL objStatusDL)
        {
            
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_GetByPK";
            SqlParameter Sqlparam;
  

            Sqlparam = new SqlParameter("@Id", SqlDbType.Int);
Sqlparam.Value = objStatusDL.Id;
Sqlcomm.Parameters.Add(Sqlparam);


            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if(!Convert.IsDBNull(dr["Id"]))
objStatusDL.Id=Convert.ToInt32(dr["Id"]);
if(!Convert.IsDBNull(dr["Name"]))
objStatusDL.Name=Convert.ToString(dr["Name"]);
if(!Convert.IsDBNull(dr["IsPublic"]))
objStatusDL.IsPublic=Convert.ToBoolean(dr["IsPublic"]);
if(!Convert.IsDBNull(dr["IsNews"]))
objStatusDL.IsNews=Convert.ToBoolean(dr["IsNews"]);
if(!Convert.IsDBNull(dr["IsProduct"]))
objStatusDL.IsProduct=Convert.ToBoolean(dr["IsProduct"]);
if(!Convert.IsDBNull(dr["IsMenu"]))
objStatusDL.IsMenu=Convert.ToBoolean(dr["IsMenu"]);

            }
             return objStatusDL;
        }

        public ArrayList SelectAll1( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrStatusDL = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach(DataRow dr in dt.Rows)
{
StatusDL objStatusDL= new StatusDL();
if(!Convert.IsDBNull(dr["Id"]))
objStatusDL.Id=Convert.ToInt32(dr["Id"]);
if(!Convert.IsDBNull(dr["Name"]))
objStatusDL.Name=Convert.ToString(dr["Name"]);
if(!Convert.IsDBNull(dr["IsPublic"]))
objStatusDL.IsPublic=Convert.ToBoolean(dr["IsPublic"]);
if(!Convert.IsDBNull(dr["IsNews"]))
objStatusDL.IsNews=Convert.ToBoolean(dr["IsNews"]);
if(!Convert.IsDBNull(dr["IsProduct"]))
objStatusDL.IsProduct=Convert.ToBoolean(dr["IsProduct"]);
if(!Convert.IsDBNull(dr["IsMenu"]))
objStatusDL.IsMenu=Convert.ToBoolean(dr["IsMenu"]);
arrStatusDL.Add(objStatusDL);
}
            }
               return arrStatusDL;
        }
        
        public DataTable SelectAll( )
        {
			
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType =  CommandType.StoredProcedure;
            Sqlcomm.CommandText =  "Status_GetAll";
            
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
          
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                
            }
               return dt;
        }

     
#endregion          
    
    }

}
